package concurrent.executors;

import java.util.Collections;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CallableAndFuture {

  public static void main(String[] args) throws ExecutionException, InterruptedException {
    ExecutorService executor;
    executor = Executors.newSingleThreadExecutor();
    Future<String> future = executor.submit(new Callable<String>() {   //接受一上callable实例
      public String call() throws Exception {
        int x = 6;
        if (x > 5) {
          throw new IllegalArgumentException();
        }
        return "MOBIN";
      }
    });
    System.out.println("任务的执行结果：" + future.get());

  }

}
